package com.yeban.test2;

import java.util.Scanner;

public class CustomerManager {
    private static final CustomerDao customerDAO = new CustomerDao();

    // 主菜单
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("\n===== 客户管理系统 =====");
            System.out.println("1. 插入客户数据");
            System.out.println("2. 修改客户数据");
            System.out.println("3. 查询所有客户信息");
            System.out.println("4. 根据编号查询客户");
            System.out.println("5. 根据姓名查询客户");
            System.out.println("0. 退出系统");
            // 在 main 方法的 while 循环中替换原来的输入代码
            System.out.print("请输入功能编号：");
            try {
                int choice = scanner.nextInt();
                switch (choice) {
                    case 1:
                        customerDAO.insertCustomer();
                        break;
                    case 2:
                        customerDAO.updateCustomer();
                        break;
                    case 3:
                        customerDAO.queryAllCustomers();
                        break;
                    case 4:
                        customerDAO.queryCustomerById();
                        break;
                    case 5:
                        customerDAO.queryCustomerByName();
                        break;
                    case 0:
                        System.out.println("退出成功！");
                        scanner.close();
                        return;
                    default:
                        System.out.println("输入有误，请重新选择！");
                }
            } catch (Exception e) {
                System.out.println("输入格式错误，请输入数字！");
                scanner.nextLine(); // 清除错误输入
                continue;
            }
        }
    }
}